app.controller("noticeCategoryController",function($scope, $location, $controller, noticeCategoryService){
    $controller('baseController',{$scope:$scope, baseService:noticeCategoryService});

    $scope.editIsuse = function (id, val, msg) {
        var bool = true;
        if (msg) {
            bool = window.confirm(msg);
        }
        if (bool) {
            var queryJson = {
                entity: {
                    id: id,
                    isuse: val
                }
            };
            noticeCategoryService.edit(queryJson).success(function (res) {
                $scope.resHandler(res, function (res) {
                    alert("修改成功");
                    $scope.findPage();
                })
            })
        }

    }

    $scope.batchEditIsuse = function (val, msg) {
        var bool = true;
        if (msg) {
            bool = window.confirm(msg);
        }
        if (bool) {
            var queryJson = {
                entity: {
                    isuse: val
                },
                ids : $scope.ids
            };
            noticeCategoryService.updateManyByIds(queryJson).success(function (res) {
                $scope.resHandler(res, function (res) {
                    alert("修改成功");
                    $('.js_checkbox').prop("checked", false);
                    $scope.findPage();
                })
            })
        }

    }
    $scope.entity = {
    };

    $scope.edit = function (direct) {
        var entity = $scope.entity;

        if (entity.name === undefined || entity.name === null || entity.name === "") {
            alert("请输入分类名称");
            return;
        }

        var queryJson = {
            entity: entity
        };
        noticeCategoryService.edit(queryJson).success(function (res) {
            $scope.resHandler(res, function (res) {
                if (direct === undefined || direct === null) {
                    $scope.entity = {};
                    alert(res.msg);
                } else {
                    location.href = direct;
                }
            })
        })
    }

    $scope.editInit = function () {
        $params = $location.search();
        if($params['id'] !== undefined) {
            var queryJson = {
                entity : {
                    id : $params['id']
                }
            };
            noticeCategoryService.find(queryJson).success(function (res) {
                $scope.resHandler(res, function () {
                    $scope.entity = res.data;
                });
            });
        }
    };

    $scope.listInit = function () {
        $scope.findPage();
    }

});
